package 图.并查集;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
/**
 * @author aodre , QQ : 480029069
 * @date 2023/8/15 17:49
 */
public class 美团笔试并查集 {
    /*
     这个题 是 纯纯 并查集
     而且技巧性 很强！
     是个 好题！
     */
}


 class Main {

    static List<Integer> get_divisors(int n) {
        List<Integer> res = new LinkedList();
        for (int i = 1 ; i <= n /i ; i++) {
            if (n%i == 0) {
                res.add(i);
                if (i!=n/i) res.add(n/i);
            }
        }
        Collections.sort(res);
        return res;
    }

    static int[] fa;

    static void init(int n) {
        fa = new int[n];
        for (int i = 0; i < n; i++) fa[i] = i;
    }
    //找到x的根节点
    static int find(int x) {
        return x == fa[x] ? x : (fa[x] = find(fa[x]));
    }
    //合并两个节点
    static void union(int x, int y) {
        fa[find(x)] = find(y);
    }

    static int getConn(int x, int y, char[] cs) {
        init(x*y+1);
        int[][] dirs = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
        for (int i = 0; i < x; i++) {
            for (int j = 0; j < y; j++) {
                for (int[] dir : dirs) {
                    int ni = i + dir[0], nj = j + dir[1];
                    if (ni < 0 || nj < 0 || ni >= x || nj >= y || cs[i*y+j] != cs[ni*y + nj])continue;
                    union(i*y+j, ni*y+nj);
                }
            }
        }

        int res = 0;
        for (int i = 0; i < x; i++) {
            for (int j = 0; j < y; j++) {
                if (find(i*y+j) == i*y+j)res++;
            }
        }
        return res;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String s = sc.nextLine();
        List<Integer> divs = get_divisors(n);
        int res = Integer.MAX_VALUE;
        for (int div : divs) {
            if (div != n)res = Math.min(res, getConn(div, n/div,s.toCharArray()));
        }
        System.out.println(res);
    }
}
